<template>
  <div>   
    <el-table :data="lst1">
        <el-table-column prop="id" label="选择"> 
            <el-checkbox-group v-model="checkList" slot-scope="scope"> 
            <el-checkbox :label="scope.row.id"></el-checkbox>
        </el-checkbox-group>
        </el-table-column>
      <el-table-column prop="title" label="标题"> </el-table-column>
      <el-table-column prop="price" label="价格"> </el-table-column>
      <el-table-column prop="userid" label="卖家"> </el-table-column>
      <el-table-column prop="count" label="数量"> 
        <template slot-scope="scope">
        <el-input-number @change="changeNum()" v-model="scope.row.min" :min="1" :max="scope.row.count"></el-input-number>
    </template>
      </el-table-column>
      <el-table-column prop="final" label="总价"> </el-table-column>
    </el-table>
    <el-button @click="gm">购买</el-button>
  </div>
</template>

<script>

export default {
    data(){
        return{
            lst1:"",
            userid:localStorage.getItem("userid"),
            checkList:[],
            token:""
        }
    },
    mounted(){
        this.getgwc()
        this.gettoken()

    },
    methods:{
        getgwc(){
            this.axios.get("/getgwc?userid="+this.userid).then(res =>{
                this.lst1 = res.data.data
                this.lst1.map((v) =>{
                    v.final = v.price * v.min
                })
                console.log(this.lst1)
            })
        },
        changeNum(){
            this.lst1.map(v=>{
                    v.final = v.price * v.min
            })
        },
        gm(){
            var data = {"checkList":this.checkList,"userid":this.userid,"token":this.token}
            this.axios.post("/gm",data).then(res =>{
                alert(res.data.msg)
            })
        },gettoken(){
            this.axios.get("/gettoken").then(res =>{
                this.token = res.data.token
            })
        }

    }

}
</script>

<style>

</style>